package cn.itsource.hrm.service.impl;

import cn.hutool.crypto.SecureUtil;
import cn.itsource.hrm.controller.vo.RegisterVo;
import cn.itsource.hrm.domain.Sso;
import cn.itsource.hrm.domain.VipBase;
import cn.itsource.hrm.mapper.SsoMapper;
import cn.itsource.hrm.mapper.VipBaseMapper;
import cn.itsource.hrm.service.ISsoService;
import cn.itsource.util.StrUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 会员登录账号 服务实现类
 * </p>
 *
 * @author chenyuqi
 * @since 2020-06-02
 */
@Service
public class SsoServiceImpl extends ServiceImpl<SsoMapper, Sso> implements ISsoService {
    @Autowired
    private VipBaseMapper vipBaseMapper;

    /**
     * 用户注册
     * @param vo
     */
    @Override
    public void register(RegisterVo vo) {


        Sso sso = new Sso();
        sso.setCreateTime(System.currentTimeMillis());
        sso.setPhone(vo.getPhoneNum());
        String salt = StrUtils.getComplexRandomString(6);
        String password = SecureUtil.md5(vo.getPassword() + salt);
        sso.setPassword(password);
        sso.setSalt(salt);
        sso.setNickName("");
        baseMapper.insert(sso);


        VipBase vipBase = new VipBase();
        vipBase.setCreateTime(System.currentTimeMillis());
        vipBase.setSsoId(sso.getId());
        vipBase.setRegChannel(1);
        vipBase.setRegTime(System.currentTimeMillis());
        vipBase.setLevel(1);
        vipBaseMapper.insert(vipBase);




    }
}
